#include "main.h"

ringblkbuf_t rbb;
param_t param;

__asm void MSR_MSP(uint32_t addr) 
{
    MSR MSP, r0
    BX r14
}

int main(void)
{
	nvic_priority_group_set(NVIC_PRIGROUP_PRE4_SUB0);
	systick_config();
	debug_gpioinit();
	// param_init(&param);
	param_read(&param);
	if (param.boot_flag == BOOT2APP_FLAG)
	{
		void (*AppJump)(void);
		AppJump = (void (*)(void))(*((uint32_t *)(APP_ADDRESS + 4)));
		SCB->VTOR = (FLASH_BASE | 0xC000);
		MSR_MSP(*(uint32_t *)APP_ADDRESS);
		AppJump();
	}
	else
	{
		blueled_gpioinit();
		uart0_init();
		usart0rx_dmainit();
		usart0tx_dmainit();
		ringblkbuf_init(&rbb);
		protocol_run();
	}
}
